<template>
	<view class="user-center">
		<view class="header-top">
			<image class="pageBg" :src="userTopBg"/>
			<u-gap height="100"/>
			<view class="userInfo flex padding align-center">
				<u-avatar :src="userInfo.zhaopian
?getImgUrl(userInfo.zhaopian):'moren'" :size="60" />
				<view class="header-name padding-left font-size-lg">				 			<!-- 是否有姓名，有则显示姓名，否则显示xuehao -->
					<view>{{userInfo.xingming?userInfo.xingming:userInfo.xuehao}}</view>
				</view>
			</view>
		</view>
		<view class="padding">
			<view class="radius user-content bgWhite">
				<u-cell-group :border="false">
					<u-cell v-for="(item,index) in userMenu" :key="index" size="large" :name="item.path" :title="item.name" :isLink="true" @click="cellClick">
						
					</u-cell>
				</u-cell-group>
			</view>
			<view class="foot-btn padding-tb">
				<u-button type="primary" text="退出登录" @click="logout"></u-button>
			</view>
		</view>
	
		<c-tab-bar :tabValue="2" />
	</view>
</template>

<script>
	import CTabBar from '@/components/cTabBar/cTabBar';
	import {userMenu} from './userMenu.js'
	import staticImgs from '@/common/utils/staticImg.js'
	import {getImgUrl} from '@/common/utils/index.js'
	import {userInfoApi} from '@/common/api/user.js'
	export default {
		name: 'User',
		components: {
			CTabBar,
		},
		data() {
			return {
				getImgUrl,
				userTopBg:staticImgs.userTopBg,
				userMenu,//用户菜单
				userInfo: {}, //用户信息
			}
		},
		onShow() {
			this.getUserInfo()
		},
		methods:{
			getUserInfo(){
				let that =this
				userInfoApi(that.$store.state.vuex_user.id).then(res=>{
					that.userInfo = res
					that.$u.vuex('vuex_user', res)
				})
			},
			cellClick(e){
				const that = this
				if(e.name){
					that.$uniRouter.navigateTo({url:e.name})
				}else{
					uni.showToast({
						title: "功能待开发",
						icon: "none",
					});
				}
			},
			logout() {
				//退出登录清toke 和用户缓存
				let that =this
				uni.showModal({
					title: '退出登录',
					content: '确定要退出登录吗？',
					success: function(res) {
						if (res.confirm) {
							uni.removeStorageSync('lifeData') //移除token 和用户信息
							that.$uniRouter.navigateTo({url:'/pages/login/login'})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		}
	}
</script>
<style>
	page{
		/* background: #f9f9f9 !important; */
		height: 100% !important;
		overflow: auto !important;
	}
</style>
<style lang="scss" scoped>
	
	.user-center{
		.header-top{
			position: relative;
			.userInfo{
				position: relative;
			}
			
		}
	}
</style>